package cn.janyd.jmall.redis.core.serializer;

import org.nustaq.serialization.FSTConfiguration;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

/**
 * @author janyd
 * @since 2020/8/18 20:31
 */
public class FstRedisSerializer implements RedisSerializer<Object> {

    private static final FSTConfiguration CONFIGURATION = FSTConfiguration.createDefaultConfiguration();

    @Override
    public byte[] serialize(Object o) throws SerializationException {
        return CONFIGURATION.asByteArray(o);
    }


    @Override
    public Object deserialize(byte[] bytes) throws SerializationException {
        if (bytes == null) {
            return null;
        }
        return CONFIGURATION.asObject(bytes);
    }
}
